# 说明: Git合并其它分支到当前分支
# 运行方式: sh git-merge-other-branch-to-current.sh | 参数1: 目标branch(枚举值在下面的描述中说明)

#获取当前分支名称
now_branch=$(git branch --show-current)
echo "当前分支:" $now_branch

#需要合并的分支
if [ "$1" == 1 ] ;then
  remote_branch="test"
elif [ "$1" == 2 ] ;then
  remote_branch="xxx"
elif [ "$1" == 3 ] ;then
  remote_branch="master"
else
 echo "参数1:目标branch的值错误(1:test; 2:xxx; 3:master)"
 exit
fi
echo "目标合并分支:" $remote_branch

#开始操作
# 切换到 {remote_branch} 分支,然后pull
git checkout $remote_branch
git pull

# 回到当前分支,pull,合并最新的 {remote_branch} 分支
git checkout $now_branch
git pull
git merge $remote_branch
git push